package com.car.dal.dao.moneys;

import java.util.HashMap;
import java.util.List;

import org.hamcrest.core.IsNull;
import com.car.bean.GridObj;
import com.car.bean.OrderObj;
import com.car.bean.PageObj;
import com.car.dal.dao.ibatis.IbatisCommonDao;
import com.car.dal.object.TgMoney;
import com.car.util.MathUtil;
import com.car.util.Page;

import net.sf.json.JSONException;
import net.sf.json.JSONObject;

public class TgMoneyDaoImpl extends IbatisCommonDao<TgMoney, Long> implements TgMoneyDao {

	@Override
	public GridObj GetList(TgMoney moeny, PageObj pageObj) {
		OrderObj order = new OrderObj();
		order.setDir("desc");
		order.setSort("id");
		// TODO Auto-generated method stub
		return super.findByPage(moeny, pageObj, order);
	}
	
	public Integer getMonCountByType(TgMoney money) {
		return this.queryForInteger("getMonCountByType", money);
	}
	
	public Integer getMonCountByType_two(TgMoney money) {
		return this.queryForInteger("getMonCountByType_two", money);
	}
	
	@Override
	public List<TgMoney> getMoneysByType(TgMoney money,Page page) {
		money.setFirstrownum(page.getFirstrownum());
		money.setPagesize(page.getPagesize());
		List<TgMoney> list=this.queryForEntityList(TgMoney.class,"getMoneysByType", money);
		return list;
	}
	
	@Override
	public List<TgMoney> getMoneysByType_two(TgMoney money,Page page) {
		money.setFirstrownum(page.getFirstrownum());
		money.setPagesize(page.getPagesize());
		List<TgMoney> list=this.queryForEntityList(TgMoney.class,"getMoneysByType_two", money);
		return list;
	}
	
	@Override
	public List<TgMoney> getMoneysByType2(TgMoney money) {
		List<TgMoney> list=this.queryForEntityList(TgMoney.class,"getMoneysByType2", money);
		return list;
	}
	
	@Override
	public List<TgMoney> getMoneysByType4(TgMoney money) {
		List<TgMoney> list=this.queryForEntityList(TgMoney.class,"getMoneysByType4", money);
		return list;
	}
	@Override
	public List<TgMoney> getMoneysByType5(TgMoney money) {
		List<TgMoney> list=this.queryForEntityList(TgMoney.class,"getMoneysByType5", money);
		if(money.getUsername().equals("sunmengmeng")){
			for(int i = 0;i<list.size();i++){
				if(list.get(i).getJd_center_key().equals("9eu7qi58lwev")){
					list.remove(i);
				}
			}
		}
		return list;
	}
	
	@Override
	public List<TgMoney> getMoneysByType3(TgMoney money) {
		List<TgMoney> list=this.queryForEntityList(TgMoney.class,"getMoneysByType3", money);
		return list;
	}
	
	@Override
	public List<TgMoney> getMoneySmtype(TgMoney money) {
		List<TgMoney> list=this.queryForEntityList(TgMoney.class,"getMoneySmtype", money);
		return list;
	}
	
	@Override
	public Integer getMonCountFpByType(TgMoney money) {
		return this.queryForInteger("getMonCountFpByType", money);
	}
	
	@Override
	public List<TgMoney> getMoneysFpByType(TgMoney money,Page page) {
		money.setFirstrownum(page.getFirstrownum());
		money.setPagesize(page.getPagesize());
		List<TgMoney> list=this.queryForEntityList(TgMoney.class,"getMoneysFpByType", money);
		return list;
	}

	@Override
	public List<TgMoney> getMoneysStaticByType(TgMoney money) {
		List<TgMoney> list=this.queryForEntityList(TgMoney.class,"getMoneysStaticByType", money);
		return list;
	}
	
	@Override
	public List<TgMoney> getMoneysStudentByType(TgMoney money) {
		List<TgMoney> list=this.queryForEntityList(TgMoney.class,"getMoneysStudentByType", money);
		return list;
	}
	
	@Override
	public List<TgMoney> getMoneysScStaticByType(TgMoney money) {
		List<TgMoney> list=this.queryForEntityList(TgMoney.class,"getMoneysScStaticByType", money);
		return list;
	}

	@Override
	public List<TgMoney> getMoneysTidianByType(TgMoney money) {
		List<TgMoney> list=this.queryForEntityList(TgMoney.class,"getMoneysTidianByType", money);
		return list;
	}
	@Override
	public List<TgMoney> getMoneysTidianDingjinByType(TgMoney money) {
		List<TgMoney> list=this.queryForEntityList(TgMoney.class,"getMoneysTidianDingjinByType", money);
		return list;
	}
	
	@Override
	public Integer getEnrollmentRecordCount(TgMoney money) {
		return this.queryForInteger("getEnrollmentRecordCount", money);
	}

	@Override
	public List<TgMoney> getEnrollmentRecord(TgMoney money, Page page) {
		money.setFirstrownum(page.getFirstrownum());
		money.setPagesize(page.getPagesize());
		List<TgMoney> list=this.queryForEntityList(TgMoney.class,"getEnrollmentRecord", money);
		return list;
	}


	@Override
	public List<TgMoney> getFullPaymentStuId(HashMap map) {
		List<TgMoney> list=this.queryForEntityList(TgMoney.class,"getFullPaymentStuId", map);
		return list;
	}

	@Override
	public Double getFullPaymentMoney(HashMap map) {
		return (double)queryForObject("getFullPaymentMoney",map);
	}

	@Override
	public List<TgMoney> getFullPaymentStuName(HashMap map) {
		List<TgMoney> list=this.queryForEntityList(TgMoney.class,"getFullPaymentStuName", map);
		return list;
	}

	@Override
	public Double getFullPaymentMoney2(HashMap map) {
		return (double)queryForObject("getFullPaymentMoney2",map);
	}

	@Override
	public List<TgMoney> getDepositDate(TgMoney money) {
		List<TgMoney> list=this.queryForEntityList(TgMoney.class,"getDepositDate", money);
		return list;
	}

	@Override
	public List<TgMoney> getFlowInformation(TgMoney tgMoney) {
		List<TgMoney> list=this.queryForEntityList(TgMoney.class,"getFlowInformation", tgMoney);
		return list;
	}

	@Override
	public Integer getPayCount(TgMoney tgMoney) {
		return this.queryForInteger("getPayCount", tgMoney);
	}

	@Override
	public Integer getRetainageCount(HashMap map) {
		return this.queryForInteger("getRetainageCount", map);
	}

	@Override
	public Double getRetainageMoneys(HashMap map) {
		return (double)queryForObject("getRetainageMoneys",map);
	}

	@Override
	public Integer getFullPaymentCount(HashMap map) {
		return this.queryForInteger("getFullPaymentCount", map);
	}

	@Override
	public Double getFullPaymentMoneys(HashMap map) {
		return (double)queryForObject("getFullPaymentMoneys",map);
	}

	@Override
	public Integer getExcelCountByDate(HashMap map) {
		return	queryForInteger("getExcelCountByDate", map);
	}

	@Override
	public Double getExcelMoneyByDate(HashMap map) {
		return (double)queryForObject("getExcelMoneyByDate",map);
	}

	@Override
	public List<TgMoney> getMoneysByType6(TgMoney money) {
		List<TgMoney> list=this.queryForEntityList(TgMoney.class,"getMoneysByType6", money);
		return list;
	}
	@Override
	public List<TgMoney> getMoneysTuanduikcByType(TgMoney money) {
		// TODO Auto-generated method stub
		List<TgMoney> list=this.queryForEntityList(TgMoney.class,"getMoneysTuanduikcByType", money);

		return list;
	}

	@Override
	public List<TgMoney> getAllMoneySmtype(TgMoney money) {
		List<TgMoney> list=this.queryForEntityList(TgMoney.class,"getAllMoneySmtype", money);
		return list;
	}
	/**
	 * 获取学员续费信息
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<String> getStu_xufei_xinzeng(long stu_id, String startTime, String endTime,Integer moneyType1) {
		TgMoney money = new TgMoney();
		money.setStu_id(stu_id);
		money.setStartTime(startTime);
		money.setEndTime(endTime);
		money.setMoneyType1(moneyType1);
		return this.queryForList("getStu_xufei_xinzeng", money);
	}

	@SuppressWarnings("unchecked")
	@Override
	public TgMoney getmoneySm_new(long stu_id) {
		TgMoney money = new TgMoney();
		try {
			money.setStu_id(stu_id);
			List<String> list = queryForList("getmoneySm_new", money);
			if(list.size() > 0) {
				JSONObject jsonObj = JSONObject.fromObject(list.get(0));  
				if(MathUtil.isNotEmpty(jsonObj.getString("smf_c"))) {
					money.setSmf_c(jsonObj.getString("smf_c"));
				}
				if(MathUtil.isNotEmpty(jsonObj.getString("smcs"))) {
					money.setSmcs(jsonObj.getString("smcs"));
				}
			}
		} catch (JSONException e) {e.printStackTrace();}
		return money;
	}
}
